home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / Log Library 1.01 / LogLibComponent ƒ / New ShowInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-03  |  6.0 KB  |  178 lines  |  [TEXT/KAHL]

  1. /*
  2.     New ShowInit.c (Derivative of Apple's ShowInit.c code).
  3.     
  4.     Code to handle the display of an icon at the bottom of the screen during startup.
  5.     This code is a modification of the original ShowInit code (see author's comments
  6.     below).  It has been modified to do a couple of things:
  7.     
  8.         1.    It uses icon families.  That means that the appropriate icon will be displayed to match the
  9.             depth of the monitor.
  10.             
  11.         2.    It loads and calls an externally defined code resource which returns a boolean value.  This
  12.             value indicates which icon family to be displayed.  Family #128 is used when the init is
  13.             able to load (verification routine returns true) and family #129 is used when the init is
  14.             unable to load (verification routine returns false).
  15.             
  16.         3.    If the init is able to load, it loads and calls an externally defined code resource to handle
  17.             the in-depth stuff.
  18.         
  19.         4.    Failure on the part of the code to find the verification routine indicates that the init cannot load.
  20.             If the icons can not be found, no icon is displayed.  If the second code resource is unavailable,
  21.             the init code just exits.
  22.             
  23.     By doing the init resource this way, this code resource can be compiled and copied into many different
  24.     files.  It provides a standard way of creating the extensions/cdevs/whatever that allows them to have
  25.     an icon displayed at startup.
  26.         
  27.     4/24/94 dn - Created (from the original).
  28.     5/7/94 dn - Following modifications:
  29.         • Doesn't use the verify code resource, always draws the good icon.
  30.         • Doesn't have a bad icon, the only icon displayed is family number 300
  31.         • Doesn't use the init code resource from #3 above.
  32.     7/3/94 dn - Modified to use with the Universal Headers.
  33.     
  34.     (view using geneva 9 point font)
  35. */
  36.  
  37. /*
  38.     Written 12:55 pm Jul 27, 1988 by jwhitnell@cup.portal.com.UUCP in 
  39.     zaphod:comp.sys.mac.programmer.  It's short enough that I'll break the UseNet 
  40.     cardinal rule and post it here:
  41.  
  42.     Simple INIT notification routine in LightSpeedC 2.15
  43. */
  44. /*
  45.     Jerry Whitnell
  46.     jwhitnell@cup.portal.com
  47.     ..!sun!cup.portal.com!jwhitnell
  48. */
  49.  
  50. /*
  51.     Also code from Think Reference v2.0.  The code comes from the section under 'Using QD Globals in an INIT'.
  52. */
  53.  
  54. #if NEW_HEADERS_AVAILABLE
  55. #include <Icons.h>
  56. #else
  57. #include <IconFamily.h>    // found in the technote 'Drawing Icons the Sytem 7 Way'
  58. #endif
  59.  
  60. #include <Finder.h>
  61. #include <GestaltEqu.h>
  62.  
  63. #include "LogLibComponent Private.h"
  64.  
  65. /*
  66.     Duplicates the QD global structure.
  67. */
  68. typedef struct {
  69.     char        privates[76];
  70.     long        randSeed;
  71.     BitMap    screenBits;
  72.     Cursor    arrow;
  73.     Pattern    dkGray;
  74.     Pattern    ltGray;
  75.     Pattern    black;
  76.     Pattern    white;
  77.     GrafPtr    thePort;
  78.     long        qdEnd;
  79. } QD_Globals;
  80.  
  81.  
  82. /*
  83.     This is where the horizontal offset is stored.  An INIT uses these values to determine where it should draw
  84.     it's icon, afterwards it updates the values for the next INIT.
  85. */
  86. extern short myHoriz:    0x092c;            // CurAppName + 28
  87. extern short myCheck:    0x092e;            // CurAppName +30
  88. extern long oldSig:        0x0a78;            // ApplScratch
  89. extern short oldHoriz:    0x0a7e;            // ApplScratch + 6
  90.  
  91. // local prototypes.
  92. void ComponentShowInit(void);
  93. void DrawTheIconFamily(short id,GrafPtr port);
  94.  
  95. /*
  96.     ComponentShowIcon
  97.     
  98.     This accesses two code resources: the first is a verification resource which lets the procedure know
  99.     which icon to display.  The second handles the 'guts' of the process.  Control is passed to this code resource
  100.     where it is supposed to do the INIT/patch/whatever thing that it is supposed to do.
  101.     
  102.     Gutted to merely display the icon at startup time.
  103. */
  104. void ComponentShowInit(){
  105.     long    oldA5;                        // a5 register value
  106.     long result;                        // result from the Gestalt call
  107.     QD_Globals qd;                        // the fake QD globals
  108.     CGrafPort    gp;                        // the color graf port to be drawing in
  109.     OSErr err;                        // os errors
  110.     GrafPtr localPtr;                    // the pointer to the port
  111.     
  112.     oldA5 = SetA5((long) &qd.qdEnd);        // Tell A5 to point to the 'fake' QD Globals
  113.     InitGraf(&qd.thePort);                // Initialize the fake QD Globals
  114.  
  115.     // This code tests the screen device type, so we can tell whether to open up a Color or B&W GrafPort.
  116.     err = Gestalt (gestaltQuickdrawVersion, &result);
  117.     
  118.     if ((err == noErr) && (result >= gestalt8BitQD))    // then this is a color mac
  119.         OpenCPort(&gp);
  120.     else                                        // then it is only black and white
  121.         OpenPort((GrafPtr)&gp);
  122.     
  123.     localPtr=(GrafPtr)(&gp);                        // cast to get the pointer to a normal graf port
  124.     
  125.     DrawTheIconFamily(300,localPtr);
  126.     
  127.     ClosePort((GrafPtr)&gp);                        // close the port
  128.     
  129.     SetA5(oldA5);                                 // Restore A5 to its previous value
  130. }
  131.  
  132. /*
  133.     DrawTheIconFamily
  134.     
  135.     Given the id of the family to draw, this routine will draw the appropriate icon family (using PlotIconID)
  136.     at the next available icon position.
  137. */
  138. void DrawTheIconFamily(short id,GrafPtr localPort){
  139.     register short hoffset;                        // horizontal offset
  140.     Rect dest;                                    // destination rectange where the icon should be drawn
  141.     
  142.     hoffset=myHoriz;                            // get the current horizontal position
  143.     asm {                                    // compute a checksum on the value
  144.             rol #1,hoffset
  145.             eor #0x1021,hoffset
  146.     }
  147.     
  148.     if (hoffset==myCheck){                        // if they match
  149.         hoffset=myHoriz;                        // use the original value
  150.     } else {                                    // otherwise
  151.         if (oldSig=='Paul')                        // if the sig is 'Paul' (I assume for compatibility reasons)
  152.             hoffset=oldHoriz;                    // use the old horizontal offset
  153.         else                                    // otherwise
  154.             hoffset=8;                        // we are the first, use 8
  155.     }
  156.     
  157.     /*
  158.         add code here to wrap the icon around?
  159.     */
  160.     
  161.     dest.bottom=localPort->portRect.bottom-8;        // set the bottom to the vertical position
  162.     dest.left=localPort->portRect.left+hoffset;        // set the left to the horizontal position
  163.     dest.top=dest.bottom-32;                        // make room for 32 bit tall icons
  164.     dest.right=dest.left+32;                        // make room for 32 bit wide icons
  165.     
  166.     hoffset += 40;                                // compute the next position
  167.     myHoriz=hoffset;                            // save it for the next INIT
  168.  
  169.     asm {                                    // compute the checksum
  170.             rol #1,hoffset
  171.             eor #0x1021,hoffset
  172.     }
  173.     
  174.     myCheck=hoffset;                            // save it for the next INIT too
  175.     
  176.     PlotIconID(&dest,atVerticalCenter+atHorizontalCenter,ttNone,id);    // draw the icon centered with no transformations
  177. }
  178.